Yacon.widget.TWindow = function(element){
	
	if(element){
		this.element = element;
		this.dataSet = this.element.dataSet;
	}
	
	//是否自动关闭
	if(element.autoClose == undefined){
		this.autoClose = true;
	}else{
		this.autoClose = element.autoClose;
	}
	
};

Yacon.widget.TWindow.prototype = {
	
	/* 展示页面信息 */
	show : function(srcLocation){
		
		var self = this;
		
		this.elementID = this.dataSet.elementID+"_window";
		var elementID = this.elementID;
		
		if(Yacon.isEmpty(this.element.width)){
			this.width = "70%";
		}else{
			this.width = this.element.width;
		}
		
		if(Yacon.isEmpty(this.element.height)){
			this.height = "";
		}else{
			this.height = Yacon.getHeightNumber(this.element.height) + "px";
		}
		
		var html = "";
		
		html += "<div class='modal fade' id='"+this.elementID+"' tabindex='-1' role='dialog' lily-container='window' lily-player='twindow' ";	
		
		if(!this.autoClose){
			html += " data-backdrop='static' ";
		}
		
		html += " >";
		
		html += "<div class='modal-dialog' style='width:"+this.width+"; ";
		
		html += "' >"
		
		html += "<div class='modal-content' style='background-color: rgba(255, 255, 255, 0.6);'>";		
		html += "<div class='modal-body modal-fluid lily-frame col' ";
		
		var style = "";
		if(this.height != ""){
			style = "height:"+this.height+";";
		}
		
		html += " style='"+style+"' ";
		
		html += ">";
		
		html += "</div>";
		html += "</div>";	
		html += "</div>";		
		html += "</div>";
		
		$("body").append(html);		
		
		/* JS填充 */
		$("#"+this.elementID).append(this.dataSet.rsp);
		
		/* Html填充 */
		this.windowPage = window.page;
		this.windowPage.windows = this;
		
		var pageHtml = this.windowPage.getHtml();
		$("#"+this.elementID+" .modal-body.modal-fluid.lily-frame ").append(pageHtml);
		
		/* 底部 padding去除 */
		$("#"+this.elementID+" .modal-body .row:first").css("padding-top","0px");
		
		$("#"+this.elementID).modal('show');
		
		$("#"+elementID).on('hidden.bs.modal', function (e) {
			
			if(Yacon.isString(self.element.beforeClose)){
				Yacon.callBack(self.element.beforeClose,[self,self.windowPage]);
			}else{
				Yacon.callBackMethod(self.element.beforeClose);
			}
			
			$("#"+elementID).remove();
			
			if(Yacon.isString(self.element.close)){
				Yacon.callBack(self.element.close,[self,self.page]);
			}else{
				Yacon.callBackMethod(self.element.close);
			}
			
			var parentSize = $(".modal .modal-dialog").length;
			
			if(parentSize > 0){
				$("body").addClass("modal-open");
			}
			
		});
		
		if(window.isIE9){
			
			if(!Yacon.isEmpty(self.element.height)){			
				self.windowPage.layout();			
			}
			
			self.loadData();
			
			self.loadEvent();
			
			Yacon.callBack(self.elementID+"_afterOnload", [self,self.windowPage]);
			
		}
		else{
			
			$("#"+elementID).on('shown.bs.modal', function (e) {
				
				if(!Yacon.isEmpty(self.element.height)){			
					self.windowPage.layout();			
				}
				
				self.loadData();
				
				self.loadEvent();
				
				Yacon.callBack(self.elementID+"_afterOnload", [self,self.windowPage]);
				
			});
			
		}

	},
	
	/* 事件装载 */
	loadEvent: function(){	
		this.windowPage.addEvents();	
	},
	
	/* 数据加载 */
	loadData: function(){
		
		if(!Yacon.isEmpty(this.dataSet)){
			
			var params = this.windowPage.element.parameter;
			
			if(!Yacon.isEmpty(params)){
				
				var state = params.state;
				
				if(state == "edit" || state == "past"){
					this.dataSet.showData();
				}
				
			}
			
/*			var type = this.dataSet.getAction("type");
			
			if(type == 2){
				this.dataSet.showData();
			}
			
			else if(type == 0){
				this.dataSet.showData();
			}*/
		}
		
	},
	
	closeWindow: function(){
		
		if(this.elementID){			
			$("#"+this.elementID).modal('hide');		
		}
		
	},
	
	layoutBefore: function(){
		
	}
	
};
